<template>
    <div style="height: 100%; width: 100%; position: relative" ref="maindev">
        <div class="pagetop" :style="pagetopstyle">
            <div style="width: 100%">
                <el-col>
                    <table style="width: 100%; font-size: 12px" border="0">
                        <tr>
                            <td>报告单元</td>
                            <td>
                                <rm-ddl-rptunit :clearable="true" defaultflag="" v-model="searchmodel.rptunitid" width="100%" :multiple_choice="false" :targetId="true" @change="rptunitidChange"></rm-ddl-rptunit>
                            </td>
                            <td>病历号</td>
                            <td>
                                <el-input v-model.trim="searchmodel.patno" clearable style="width: 100%" placeholder="请输入病历号"></el-input>
                            </td>
                            <td>病人来源</td>
                            <td style="display: flex">
                                <el-select v-model="searchmodel.pattypecode" @dblclick.native="popMultipleChk(searchmodel.pattypecode, 'pattypecode', pattypeOption, '病人类型选择')" filterable clearable style="width: 100%" placeholder="请选择或双击开窗">
                                    <el-option v-for="(item, index) in pattypeOption" :value="item.data" :label="item.display" :key="index"></el-option>
                                </el-select>
                            </td>
                            <td>床号</td>
                            <td>
                                <el-input v-model="searchmodel.bedno" style="width: 100%" placeholder="请输入床号"></el-input>
                            </td>
                            <td></td>
                            <td style="text-align: left">
                                <el-button @click="readcard()" style="width: 80px">读卡</el-button>
                            </td>
                        </tr>
                        <tr>
                            <!-- <td>标本日期</td> -->
                            <td>
                                <el-dropdown @command="handleCommand" style="font-size: 12px">
                                    <u class="el-dropdown-link">
                                        {{ datename }}
                                    </u>
                                    <el-dropdown-menu slot="dropdown">
                                        <el-dropdown-item command="标本日期">
                                            <font font-size="12px">标本日期</font>
                                        </el-dropdown-item>
                                        <el-dropdown-item command="报告日期">
                                            <font font-size="12px">报告日期</font>
                                        </el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </td>
                            <td>
                                <el-date-picker type="datetime" v-model="searchmodel.samplestartdt" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%; min-width: 100px" :clearable="false"></el-date-picker>
                            </td>
                            <td align="center">至</td>
                            <td>
                                <el-date-picker type="datetime" v-model="searchmodel.sampleenddt" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%; min-width: 100px" :clearable="false"> </el-date-picker>
                            </td>
                            <td>姓名</td>
                            <td>
                                <el-input v-model.trim="searchmodel.patname" clearable style="width: 100%" placeholder="请输入姓名"></el-input>
                            </td>
                            <td>申请科室</td>
                            <td>
                                <el-select v-model="searchmodel.reqdept" @dblclick.native="popMultipleChk(searchmodel.reqdept, 'reqdept', deptOption, '申请科室选择')" filterable clearable style="width: 100%" placeholder="请选择或双击开窗">
                                    <el-option v-for="(item, index) in deptOption" :value="item.data" :label="item.display" :key="index"></el-option>
                                </el-select>
                            </td>
                            <td>标本类型</td>
                            <td>
                                <rm-ddl-common v-model="searchmodel.specimensearch" datatype="specimen" irrelevant="specimenShowIrrelevant" @change="specimenChange"></rm-ddl-common>
                            </td>
                        </tr>
                        <tr>
                            <td>标本号</td>
                            <td>
                                <el-input v-model="searchmodel.sampleno" placeholder="请输入标本号" style="width: 100%"></el-input>
                            </td>
                            <td>急诊标志</td>
                            <td>
                                <el-select v-model="searchmodel.emerflag" placeholder="请选择" style="width: 100%">
                                    <el-option key="all" label="全部" value="all"></el-option>
                                    <el-option key="0" label="常规" value="0"></el-option>
                                    <el-option key="1" label="加急" value="1"></el-option>
                                </el-select>
                            </td>
                            <td>病区</td>
                            <td>
                                <rm-ddl-common :appendtobody="true" datatype="ward" dataname="病区" v-model="searchmodel.reqwardno" width="100%" @change="wardChange"></rm-ddl-common>
                            </td>
                            <td>备注</td>
                            <td>
                                <el-input size="small" style="width: 100%" v-model="searchmodel.reportcomm" @dblclick.native="reportcommDlg = true" placeholder="手工输入 | 双击开窗"></el-input>
                            </td>
                            <td colspan="5" style="align: right">
                                <el-link :underline="false" @click="btn_openselEvent">{{ showsearchbottom ? "收起▲" : "展开▼" }}</el-link>
                                <el-button icon="el-icon-search" v-has="'PINQUERY'" type="primary" @click="btnInitQuery()">查询</el-button>
                                <el-button @click="setExportColumn">导出列设置</el-button>
                                <el-button icon="el-icon-delete" @click="btnClear()">清除</el-button>
                                <el-button icon="el-icon-upload2" @click.native="btnExport()">导出</el-button>
                            </td>
                        </tr>
                        <tr v-show="showsearchbottom">
                            <td>报告项目</td>
                            <td>
                                <rm-ddl-rptitem prgno="LIS442" isAllRpt="1" v-model="searchmodel.rptitemcode" width="100%" :appendtobody="true" :rptunitid="txtrptunit" @change="rptitemChange"></rm-ddl-rptitem>
                            </td>
                            <td>条码号</td>
                            <td>
                                <el-input v-model.trim="searchmodel.barcode" clearable style="width: 100%" placeholder="请输入条码号"></el-input>
                            </td>
                            <td>申请医生</td>
                            <td>
                                <rm-ddl-common datatype="userinfo" dataname="用户" v-model="searchmodel.reqdocno" width="100%" @change="reqdocChange"></rm-ddl-common>
                            </td>
                            <td>混样</td>
                            <td>
                                <el-select v-model="searchmodel.mix" placeholder="请选择" style="width: 100%">
                                    <el-option key="0" label="剔除核酸混检条码" value="0"></el-option>
                                    <el-option key="1" label="仅包含核酸混检条码" value="1"></el-option>
                                    <el-option key="2" label="剔除核酸（被混样）条码" value="2"></el-option>
                                </el-select>
                            </td>
                            <td colspan="2" style="text-align: left; padding-left: 30px">
                                <el-checkbox v-model="searchmodel.onlymed" true-label="1" false-label="0">仅显示细菌阳性结果</el-checkbox>
                            </td>
                        </tr>
                        <tr v-show="showsearchbottom">
                            <td>临床诊断</td>
                            <td>
                                <el-input size="small" style="width: 100%" v-model="searchmodel.patdiag" placeholder="请输入临床诊断"></el-input>
                            </td>
                            <td>耐药机制</td>
                            <td>
                                <el-select v-model="searchmodel.rescode" @dblclick.native="popMultipleChk(searchmodel.rescode, 'rescode', rescodeOption, '耐药机制选择')" filterable clearable style="width: 100%" placeholder="请选择或双击开窗">
                                    <el-option v-for="(item, index) in rescodeOption" :value="item.data" :label="item.display" :key="index"></el-option>
                                </el-select>
                            </td>
                            <td>多项目条件</td>
                            <td style="white-space: nowrap">
                                <el-select v-model="searchmodel.resultcomb" clearable style="width: 80%">
                                    <el-option v-for="(item, index) in resultcombOption" :value="item.data" :label="item.display" :key="index"></el-option>
                                </el-select>
                                <el-button @click="OpenResultComb()">自定义</el-button>
                            </td>
                            <td>送检目的</td>
                            <td style="white-space: nowrap">
                                <el-input v-model.trim="searchmodel.reqreason" clearable style="width: 100%" placeholder="请输入送检目的"></el-input>
                            </td>
                            <td></td>
                            <td style="text-align: left; padding-left: 30px; white-space: nowrap">
                                <span style="border: solid 1px #cccccc">
                                    <el-radio-group v-model="searchmodel.checkauditstatus">
                                        <el-radio :label="0">全部</el-radio>
                                        <el-radio :label="1">已审核</el-radio>
                                        <el-radio :label="2">未审核</el-radio>
                                    </el-radio-group>
                                </span>
                            </td>
                            <!-- <td colspan="2" style="text-align:left;padding-left:30px;">
                                <el-checkbox v-model="searchmodel.onlyselect" true-label="1" false-label="0">仅显示所选择的报告项目</el-checkbox>
                            </td> -->
                        </tr>
                        <tr v-show="showsearchbottom">
                            <td>报告单元多选</td>
                            <td>
                                <rm-ddl-rptunit prgno="LIS442" :multiple_choice="true" v-model="searchmodel.rptunitidlist" clearable width="100%" @change="rptunitlistChange"></rm-ddl-rptunit>
                            </td>
                            <td>审核者</td>
                            <td>
                                <rm-ddl-common datatype="userinfo" dataname="用户" v-model="searchmodel.chkuserno" width="100%" @change="chkuserChange"></rm-ddl-common>
                            </td>
                            <td>送检医院</td>
                            <td>
                                <rm-ddl-common datatype="hospital" dataname="医院" v-model="searchmodel.hoscode" width="100%" @change="hosChange"></rm-ddl-common>
                            </td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td style="text-align: left; padding-left: 30px; white-space: nowrap">
                                <span style="border: solid 1px #cccccc">
                                    <el-radio-group v-model="searchmodel.checkprintstatus">
                                        <el-radio :label="0">全部</el-radio>
                                        <el-radio :label="1">已打印</el-radio>
                                        <el-radio :label="2">未打印</el-radio>
                                    </el-radio-group>
                                </span>
                            </td>
                            <!-- <td colspan="2" style="text-align:left;padding-left:30px;">
                                <el-checkbox v-model="searchmodel.onlylast" true-label="1" false-label="0">仅显示病人最后一次的报告</el-checkbox>
                            </td> -->
                        </tr>
                    </table>
                </el-col>
            </div>
        </div>
        <div :style="pagecenter">
            <div class="pagemain">
                <vxe-table :data="tableData" :loading="loading" :keyboard-config="keyConfig" :keyboard-local-config="keyLocalConfig" :select-config="selectConfig" :sort-config="{ trigger: 'cell' }" :edit-config="{ trigger: 'click', mode: 'cell' }" class="editable-footer" border fit height="auto" header-align="center" weight="auto" highlight-current-row highlight-hover-row highlight-hover-column show-footer ref="xTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" :start-index="(tablePage.currentPage - 1) * tablePage.pageSize" stripe :key="xTablekey">
                    <vxe-table-column :key="item.field" :field="item.field" :title="item.title" v-for="item in tableColumn" align="center" :width="item.width" sortable :sort-width="item.field == 'rptunitid' ? 20 : 0"></vxe-table-column>
                </vxe-table>
            </div>
            <div class="pagebottom">
                <vxe-pager background size="small" :current-page="tablePage.currentPage"
                    :page-size="tablePage.pageSize" :total="tablePage.total"
                    :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
                    @page-change="handlePageChange">
                </vxe-pager>
            </div>
        </div>
        <!--报告单备注开窗-->
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择备注" :visible.sync="reportcommDlg">
            <rm-pop-common ref="popcom" @change="reportcommchange" @cancel="reportcommDlg = false" kindno="reportcomm" datatype="seccode"></rm-pop-common>
        </el-dialog>
        <!--病人来源/申请科室/耐药机制多选-->
        <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="dlgTitle" :visible.sync="multiPatsourceVisible" :destroy-on-close="true">
            <rm-SqlMultiple :leftOption="leftOption" :rightOption="rightOption" :name="fieldname" @change="closedialog"></rm-SqlMultiple>
        </el-dialog>
        <!--多项目条件自定义-->
        <el-dialog width="850px" height="600px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="结果组合查询条件" :visible.sync="bResultComb" :destroy-on-close="true">
            <div style="height: 90px" v-show="bSaveResultComb">
                <table style="width: 100%; font-size: 12px">
                    <col style="width: 10%" />
                    <col style="width: 23%" />
                    <col style="width: 10%" />
                    <col style="width: 23%" />
                    <col style="width: 10%" />
                    <col style="width: 23%" />
                    <tr>
                        <td>条件代码</td>
                        <td>
                            <el-input v-model="saveobj.queryresultno" style="width: 100%" ref="input1" @keyup.enter.native="NextFocus(1)"></el-input>
                        </td>
                        <td>条件名称</td>
                        <td>
                            <el-input v-model="saveobj.queryresultname" style="width: 100%" ref="input2" @keyup.enter.native="NextFocus(2)"></el-input>
                        </td>
                        <td>用户</td>
                        <td>
                            <rm-ddl-common datatype="userinfo" dataname="用户" v-model="saveobj.createuser" width="100%" :disabled="utype != 'G'"></rm-ddl-common>
                        </td>
                    </tr>
                    <tr>
                        <td>备注</td>
                        <td colspan="5">
                            <el-input type="textarea" v-model="saveobj.description" rows="2" ref="input3" @keyup.enter.native="NextFocus(3)"></el-input>
                        </td>
                    </tr>
                </table>
            </div>
            <div style="text-align: right; height: 30px">
                <el-button icon="el-icon-save" style="align: right" @click="btnSure()" v-show="!bSaveResultComb" type="primary">确定</el-button>
                <el-button icon="el-icon-save" style="align: right" @click="btnCancel()" v-show="!bSaveResultComb">取消</el-button>
                <el-button icon="el-icon-plus" style="align: left" @click="addItem(1)">新增明细</el-button>
                <el-button icon="el-icon-delete" style="align: left" @click="delItem(1)">删除明细</el-button>
                <el-button icon="el-icon-save" style="align: right" @click="btnToSave()" v-show="!bSaveResultComb && addPower">另存为</el-button>
                <el-button icon="el-icon-save" style="align: right" @click="btnSave()" v-show="bSaveResultComb" type="primary">保存</el-button>
                <el-button icon="el-icon-save" style="align: right" @click="btnGoBack()" v-show="bSaveResultComb">返回</el-button>
            </div>
            <div style="height: 270px">
                <vxe-table show-overflow ref="nomatch_table" :data.sync="ComList" height="auto" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" @cell-dblclick="CellDblclick" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe header-align="center">
                    <vxe-table-column field="seq" title="序号" align="center" width="55" :edit-render="{ name: 'input' }" sortable></vxe-table-column>
                    <vxe-table-column field="rpt_itemname" title="报告项目(双击弹窗)" width="145" :edit-render="{ name: 'input', autoselect: true, attrs: { readonly: true } }" sortable></vxe-table-column>
                    <vxe-table-column field="resistrules" title="耐药机制" width="150" :edit-render="{type: 'default'}">
                        <template v-slot="{ row }">
                            <el-select v-model="row.resistrules"  @dblclick.native="popMultipleChk_R(row.resistrules, 'resistrules', rescodeOption, '耐药机制选择')" style="width: 100%;" filterable clearable>
                                <el-option v-for="(item, index) in rescodeOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                            </el-select>
                        </template>
                    </vxe-table-column>
                    <vxe-table-column field="lowlimit" title="数值结果<" width="90" :edit-render="{ name: 'input', autoselect: true }" sortable></vxe-table-column>
                    <vxe-table-column field="uplimit" title="数值结果>" width="90" :edit-render="{ name: 'input', autoselect: true }" sortable></vxe-table-column>
                    <vxe-table-column field="txtoperator" title="文字结果条件" width="95" sortable>
                        <template v-slot="{ row }">
                            <el-select v-model="row.txtoperator" placeholder="请选择">
                                <el-option v-for="item in txtoperatorOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                            </el-select>
                        </template>
                    </vxe-table-column>
                    <vxe-table-column field="txtresults" title="文字结果（多个,隔开）" width="160" :edit-render="{ name: 'input', autoselect: true }" sortable></vxe-table-column>
                    <vxe-table-column field="txtlike" sortable title="文字模糊匹配" width="100" align="center">
                        <template v-slot="{ row }">
                            <el-checkbox v-model="row.txtlike" true-label="1" false-label="0"></el-checkbox>
                        </template>
                    </vxe-table-column>
                    <vxe-table-column field="mustinclude" title="必选条件" width="60" align="center">
                        <template v-slot="{ row }">
                            <el-checkbox v-model="row.mustinclude" true-label="1" false-label="0"></el-checkbox>
                        </template>
                    </vxe-table-column>
                </vxe-table>
            </div>
        </el-dialog>
        <!--选择报告项目弹窗-->
        <el-dialog width="1000px" top="10px" :append-to-body="true" :close-on-click-modal="false" title="选择报告项目" :visible.sync="rpt_itemdialog" :destroy-on-close="true">
            <rm-pop-rptitem prgno="LIS442" @cancel="rpt_itemdialog = false" :isAllRpt="1" @selitem="rpt_itemchange" :rptunitid="txtrptunit"></rm-pop-rptitem>
        </el-dialog>
        <!--导出列选择-->
        <el-dialog title="导出列选择" :visible.sync="chooseColumndialogVisible" width="380px" v-el-drag-dialog :close-on-click-modal="false" v-if="chooseColumndialogVisible">
            <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn" ref="excolset"></rm-excolsetting>
        </el-dialog>
        <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn" ref="excolset" v-show="false"></rm-excolsetting>
        <el-dialog width="1000px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="耐药机制选择" :visible.sync="dialogMultipleVisible_R" :destroy-on-close="true">
            <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="closedialog_R"></rm-SqlMultiple>
        </el-dialog>
    </div>
</template>
<script type="text/javascript">
import XE from "xe-utils"; //引入工具类
import RmExcolsetting from "@/components/rmcompents/rm_excolsetting.vue";
export default {
    name: "LIS442",
    components: { RmExcolsetting },
    data() {
        return {
            pagetopstyle: {
                height: "105px",
            },
            pagecenter: {
                position: "absolute",
                top: "108px",
                bottom: "0px",
                overflow: "auto",
                width: "100%",
                left: "0px",
            },
            tableheight: "auto",
            showsearchbottom: false, //查询框展开
            searchmodel: {
                //查询框初始值
                rptunitid: "", //报告单元
                patno: "", //病例号
                pattypecode: "", //病人来源
                bedno: "", //床号
                samplestartdt: XE.toDateString(new Date(), "yyyy-MM-dd 00:00:00"), //标本起始日期
                sampleenddt: XE.toDateString(new Date(), "yyyy-MM-dd 23:59:59"), //标本结束日期
                patname: "", //姓名
                reqdept: "", //申请科室
                specimensearch: "", //标本
                sampleno: "", //标本号
                emerflag: "", //急诊标志
                reqwardno: "", //病区
                reportcomm: "", //备注
                rptitemcode: "", //报告项目
                barcode: "", //条码号
                reqdocno: "", //申请医生
                mix: "", //混样
                onlymed: "0", //仅显示细菌阳性结果
                patdiag: "", //临床诊断
                rescode: "", //耐药机制
                resultcomb: "", //多项目条件
                checkauditstatus: 0, //审核状态
                onlyselect: "0", //仅显示所选择的报告项目
                rptunitidlist: "", //报告单元多选
                chkuserno: "", //审核者
                hoscode: "", //送检医院
                checkprintstatus: 0, //打印状态
                onlylast: "0", //仅显示病人最后一次报告
                reqreason: "",//送检目的
            },
            saveobj: {
                queryresultno: "",
                queryresultname: "",
                createuser: "",
                description: "",
            },
            tablePage: {
                total: 0,
                currentPage: 1,
                pageSize: 50,
            },
            leftOption: [],
            rightOption: [],
            fieldname: "",
            dlgTitle: "",
            multiPatsourceVisible: false,
            readcardcmdline: "",
            resultcombOption: [],
            ComList: [],
            tempCombList: [],
            bResultComb: false,
            pickerOptions: {
                shortcuts: [
                    {
                        text: "今天",
                        onClick(picker) {
                            picker.$emit("pick", new Date());
                            _that.samplestartdt = new Date();
                            _that.sampleenddt = new Date();
                        },
                    },
                ],
            },
            bSaveResultComb: false,
            addPower: false,
            reportcommDlg: false, //报告备注弹框
            pattypeOption: [],
            rescodeOption: [],
            deptOption: [],
            txtoperatorOptions: [
                {
                    value: "In",
                    label: "等于",
                },
                {
                    value: "NotIn",
                    label: "不等于",
                },
            ],
            txtrptunit: "",
            rpt_itemdialog: false,
            selrow: {},
            dialogSetting: false,
            //检索结果
            tableData: [],
            tableColumn: [],
            loading: false,
            keyConfig: {
                isEdit: true,
            },
            keyLocalConfig: {
                isArrow: true,
                isDel: true,
                isTab: true,
            },
            selectConfig: {
                tigger: "row",
            },
            xTablekey: 0,
            //导出
            excolPro: "lis442",
            chooseColumndialogVisible: false,
            allTableCol: [],
            datename: "标本日期",
            // exportwithreportinfo: "",//报告结果导出时同时导出报告单信息
            // exportwithreportdateformat: "",//报告结果导出时同时导出报告单日期格式
            option1 : [],
            option2 : [],
            dialogMultipleVisible_R: false,
            specimenname: "",
            reqwardname: "",
            rptitemname: "",
            reqdocname: "",
            rptunitsname: "",
            chkusername: "",
            hosname: "",
            rptunitname: "",
        };
    },
    created() {
        this.loginUser();
        this.initPage();
    },
    mounted() {
		this.$refs.excolset.colSettingToDB();
	},
    updated() {},
    watch: {},
    methods: {
        handleCommand(name) {
            this.datename = name;
        },
        loginUser() {
            this.utype = this.$tool.getSession(this.$tool.loginutype);
            if (this.utype == "G") {
                this.saveobj.createuser = "_Global_";
            } else {
                this.saveobj.createuser = this.$tool.getSession(this.$tool.loginusername);
            }
        },
        //页面初始化
        async initPage() {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS4/LIS442",
                    method: "post",
                    data: {
                        action: "InitPage",
                        samplestartdt: this.searchmodel.samplestartdt,
                        sampleenddt: this.searchmodel.sampleenddt,
                    },
                });

                // this.exportwithreportinfo = res.exportwithreportinfo;
                // this.exportwithreportdateformat = res.exportwithreportdateformat;
                this.readcardcmdline = res.readcardcmdline;
                this.resultcombOption = res.option.resultcombOption;
                this.pattypeOption = res.option.pattypeOption;
                this.rescodeOption = res.option.rescodeOption;
                this.deptOption = res.option.deptOption;
            } catch (e) {
                this.$message.warning(e);
            }
        },
        //双击多选
        popMultipleChk(e, fieldname, option, title) {
            let temp = XE.clone(option, true);
            this.leftOption = [];
            this.rightOption = [];
            if (e != "") {
                let k = e.split(",");
                k.forEach((item) => {
                    let ndata = temp.find((m) => m.data == item);
                    if (ndata != undefined && ndata != null) {
                        this.rightOption.push(ndata);
                    }
                });
                temp.forEach((item) => {
                    if (k.indexOf(item.data + "") < 0) {
                        this.leftOption.push(item);
                    }
                });
            } else {
                this.leftOption = temp;
            }
            this.fieldname = fieldname;
            this.dlgTitle = title;
            this.multiPatsourceVisible = true;
        },
        //关闭病人来源多选
        closedialog(value, name) {
            if (value != "close") {
                this.searchmodel[name] = value;
            }
            this.multiPatsourceVisible = false;
        },
        readcard() {
            if (typeof jsObj != "undefined") {
                var s = jsObj.ReadCard(this.readcardcmdline);
                this.searchmodel.patno = s;
            } else {
                this.$alert("请使用" + this.$pub.clientname + "打开系统", "错误", {
                    confirmButtonText: "确定",
                });
            }
        },
        OpenResultComb() {
            //无需初始化表格内的数值，方便重复查询
            //自定义与选择查询重叠||二选一，待测试
            //先满足表格直接查询,再考虑满足保存，可以优先画好全部界面。
            this.ComList = XE.clone(this.tempCombList, true);
            this.bResultComb = true;
        },
        handlePageChange({ currentPage, pageSize }) {
            this.tablePage.currentPage = currentPage;
            this.tablePage.pageSize = pageSize;
            this.btnQuery();
        },
        btnInitQuery(){
            this.tablePage.currentPage = 1;
            this.btnQuery();
        },
        btnQuery() {
            this.loading = true;
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS442",
                    method: "post",
                    data: {
                        action: "QueryData",
                        ...this.searchmodel,
                        datename: this.datename == "标本日期" ? "1" : "2",
                        comblist: this.tempCombList,
                        pagesize: this.tablePage.pageSize,
                        currentpage: this.tablePage.currentPage,
                        ispage: "1",
                    },
                })
                .then((res) => {
                    this.tableColumn = res.Cols;
                    this.tableData = res.Data;
                    this.tablePage.total = res.total;
                    this.loading = false;
                })
                .catch((e) => {
                    this.$message.error(e);
                    this.loading = false;
                });
        },
        btnClear() {
            this.btn_openselEvent();
            this.showsearchbottom = false;
            this.loading = false;
            this.tableData = [];
            this.tempCombList = [];
            this.ComList = [];
            this.searchmodel = {
                //查询框初始值
                rptunitid: "", //报告单元
                patno: "", //病例号
                pattypecode: "", //病人来源
                bedno: "", //床号
                samplestartdt: XE.toDateString(new Date(), "yyyy-MM-dd"), //标本起始日期
                sampleenddt: XE.toDateString(new Date(), "yyyy-MM-dd"), //标本结束日期
                patname: "", //姓名
                reqdept: "", //申请科室
                specimensearch: "", //标本
                sampleno: "", //标本号
                emerflag: "", //急诊标志
                reqwardno: "", //病区
                reportcomm: "", //备注
                rptitemcode: "", //报告项目
                barcode: "", //条码号
                reqdocno: "", //申请医生
                mix: "", //混样
                onlymed: "0", //仅显示细菌阳性结果
                patdiag: "", //临床诊断
                rescode: "", //耐药机制
                resultcomb: "", //多项目条件
                checkauditstatus: 0, //审核状态
                onlyselect: "0", //仅显示所选择的报告项目
                rptunitidlist: "", //报告单元多选
                chkuserno: "", //审核者
                hoscode: "", //送检医院
                checkprintstatus: 0, //打印状态
                onlylast: "0", //仅显示病人最后一次报告
            };
        },
        specimenChange(code, name) {
            this.searchmodel.specimensearch = code;
            this.specimenname = name;
        },
        wardChange(code, name) {
            this.searchmodel.reqwardno = code;
            this.reqwardname = name;
        },
        rptitemChange(code, name) {
            this.searchmodel.rptitemcode = code;
            this.rptitemname = name;
        },
        reqdocChange(code, name) {
            this.searchmodel.reqdocno = code;
            this.reqdocname = name;
        },
        rptunitlistChange(code, name) {
            this.searchmodel.rptunitidlist = code;
            this.rptunitsname = name;
        },
        chkuserChange(code, name) {
            this.searchmodel.chkuserno = code;
            this.chkusername = name;
        },
        hosChange(code, name) {
            this.searchmodel.hoscode = code;
            this.hosname = name;
        },
        btnExport() {
            var rightlocalStorage = JSON.parse(window.localStorage.getItem(this.excolPro + "exportCol"));
            let tableColumn = this.$refs.xTable.getColumns();
            let exportColumn = [];
            if (rightlocalStorage && rightlocalStorage.length > 0) {
                rightlocalStorage.forEach((item) => {
                    exportColumn.push({
                        title: item.extitle ? item.extitle : item.title,
                        field: item.property,
                    });
                });
            } else {
                tableColumn.forEach((item) => {
                    exportColumn.push({ title: item.title, field: item.property });
                });
            }
            //获取全部数据
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS442",
                    method: "post",
                    data: {
                        action: "QueryData",
                        ...this.searchmodel,
                        datename: this.datename == "标本日期" ? "1" : "2",
                        comblist: this.tempCombList,
                        pagesize: this.tablePage.pageSize,
                        currentpage: this.tablePage.currentPage,
                        ispage: "0",
                    },
                })
                .then((res) => {
                    let filtertxt = this.getExportFilter();
                    this.$pub.exportTableExcel(res.Data, exportColumn, "LIS442 报告结果导出.xlsx", filtertxt);
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        // 获取当前导出文件的所有查询条件
        getExportFilter() {
            let filtertxt = this.datename + ":" + XE.toDateString(this.searchmodel.samplestartdt, "yyyy-MM-dd HH:mm:ss") + "至" + XE.toDateString(this.searchmodel.sampleenddt, "yyyy-MM-dd HH:mm:ss") + "; ";
            if(this.searchmodel.rptunitid) filtertxt += "报告单元:" + this.rptunitname + "; ";
            if(this.searchmodel.patno) filtertxt += "病历号:" + this.searchmodel.patno + "; ";
            if(this.searchmodel.pattypecode) filtertxt += "病人来源:" + this.getOptionName(this.pattypeOption.filter((item) =>  ("," + this.searchmodel.pattypecode + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if(this.searchmodel.bedno) filtertxt += "床号:" + this.searchmodel.bedno + "; ";
            if(this.searchmodel.patname) filtertxt += "姓名:" + this.searchmodel.patname + "; ";
            if(this.searchmodel.reqdept) filtertxt += "申请科室:" + this.getOptionName(this.deptOption.filter((item) =>  ("," + this.searchmodel.reqdept + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if(this.searchmodel.specimensearch) filtertxt += "标本类型:" + this.specimenname + "; ";
            if(this.searchmodel.sampleno) filtertxt += "标本号:" + this.searchmodel.sampleno + "; ";
            if(this.searchmodel.emerflag) filtertxt += "急诊标志:" + this.getEmerFlagName() + "; ";
            if(this.searchmodel.reqwardno) filtertxt += "病区:" + this.reqwardname + "; ";
            if(this.searchmodel.reportcomm) filtertxt += "备注:" + this.searchmodel.reportcomm + "; ";
            if(this.searchmodel.rptitemcode) filtertxt += "报告项目:" + this.rptitemname + "; ";
            if(this.searchmodel.barcode) filtertxt += "条码号:" + this.searchmodel.barcode + "; ";
            if(this.searchmodel.reqdocno) filtertxt += "申请医生:" + this.reqdocname + "; ";
            if(this.searchmodel.mix) filtertxt += "混样:" + (this.searchmodel.mix == "0" ? "剔除核酸混检条码" : this.searchmodel.mix == "1" ? "仅包含核酸混检条码" : "剔除核酸（被混样）条码") + "; ";
            if(this.searchmodel.onlymed == "1") filtertxt += "仅显示细菌阳性结果; ";
            if(this.searchmodel.patdiag) filtertxt += "临床诊断:" + this.searchmodel.patdiag + "; ";
            if(this.searchmodel.rescode) filtertxt += "耐药机制:" + this.getOptionName(this.rescodeOption.filter((item) =>  ("," + this.searchmodel.rescode + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if(this.searchmodel.resultcomb) filtertxt += "多项目条件:" + this.getOptionName(this.resultcombOption.filter((item) =>  this.searchmodel.resultcomb == item.data)) + "; ";
            if(this.searchmodel.reqreason) filtertxt += "送检目的:" + this.searchmodel.reqreason + "; ";
            filtertxt += "审核状态:" + (this.searchmodel.checkauditstatus == 1 ? "已审核" : this.searchmodel.checkauditstatus == 2 ? "未审核" : "全部") + "; ";
            if(this.searchmodel.rptunitidlist) filtertxt += "报告单元多选:" + this.rptunitsname + "; ";
            if(this.searchmodel.chkuserno) filtertxt += "审核者:" + this.chkusername + "; ";
            if(this.searchmodel.hoscode) filtertxt += "送检医院:" + this.hosname + "; ";
            filtertxt += "打印状态:" + (this.searchmodel.checkprintstatus == 1 ? "已打印" : this.searchmodel.checkprintstatus == 2 ? "未打印" : "全部") + "; ";
            return filtertxt;
        },
        getEmerFlagName() {
            let name = "";
            switch(this.searchmodel.emerflag) {
                case "all":
                    name = "全部";
                    break;
                case "0":
                    name = "常规";
                    break;
                case "1":
                    name = "加急";
                    break;
            }
            return name;
        },
        getOptionName(option) {
            if (option && option.length > 0) {
                let optionname = "";
                option.forEach((item) => {
                    if(item.hasOwnProperty("label")) {
                        optionname += item.label + ",";
                    } else {
                        optionname += item.display + ",";
                    }
                });
                return optionname.substring(0, optionname.length - 1);
            } else {
                return "";
            }
        },
        CellDblclick({ row, column }) {
            // 报告项目弹窗
            if (column.property == "rpt_itemname") {
                this.selrow = row;
                this.rpt_itemdialog = true;
            }
        },
        rpt_itemchange(code, name) {
            this.selrow.rpt_itemcode = code;
            this.selrow.rpt_itemname = name;
            this.getResultArea(2, code);
            this.rpt_itemdialog = false;
        },
        async getResultArea(flag, rpt_itemcode) {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS4/LIS442",
                    method: "post",
                    data: {
                        action: "get_resultarea",
                        rpt_itemcode: rpt_itemcode,
                    },
                });
                console.log(res);
                if (flag == "1") {
                    this.searchobj.result_min = res[0].ref_l;
                    this.searchobj.result_max = res[0].ref_h;
                } else if (flag == "2") {
                    this.selrow.lowlimit = res[0].ref_l;
                    this.selrow.uplimit = res[0].ref_h;
                }
            } catch (e) {
                this.$message.warning(e);
            }
        },
        addItem() {
            this.$refs.nomatch_table
                .insert({
                    queryresultno: this.saveobj.queryresultno,
                    seq: this.$refs.nomatch_table.tableFullData.length > 0 ? (Math.floor(this.$refs.nomatch_table.tableFullData[this.$refs.nomatch_table.tableFullData.length - 1].seq / 10) + 1) * 10 : 10,
                    txtoperator: "In",
                    txtlike: 0,
                    mustinclude: "1",
                    resistrules:"",
                })
                .then(({ row }) => {
                    this.$nextTick(() => {
                        this.$refs.nomatch_table.setCurrentRow(row);
                    });
                });
        },
        delItem() {
            try {
                var delrow = this.$refs.nomatch_table.getCurrentRow();
                if (delrow) {
                    var alld = this.$refs.nomatch_table.tableData;
                    var rowindex = alld.indexOf(delrow);
                    this.$refs.nomatch_table.remove(delrow);
                    let havedata = this.$refs.nomatch_table.tableData;
                    if (havedata.length > 0) {
                        if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                        let selectrow = havedata[rowindex];
                        this.$refs.nomatch_table.setCurrentRow(selectrow);
                    } else {
                        this.$message({
                            message: "请先选中要删除的明细！",
                            type: "warning",
                        });
                        this.$refs.nomatch_table.setCurrentRow(null);
                    }
                }
            } catch (e) {
                console.log("error", e);
            }
        },
        btnToSave() {
            this.bSaveResultComb = true;
            setTimeout(() => {
                this.$refs.input1.focus();
            }, 30);
        },
        async btnSave() {
            try {
                let data = this.$refs.nomatch_table.getTableData().fullData;
                for (let i = 0, len = data.length; i < len; i++) {
                    let tempseq = (i + 1) * 10;
                    if (tempseq !== data[i].seq) {
                        data[i].seq = tempseq;
                    }
                    data[i].queryresultno = this.saveobj.queryresultno; //修正主键
                }
                const res = await this.$tool.request({
                    url: "LIS/LIS1/LIS156",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "addsearchadition",
                        utype: 1,
                        addparam: this.saveobj,
                        upt: data,
                    },
                });
                if (res.errcode == "1") {
                    this.$message.success("保存成功！");
                    this.Freshcomb(); //保存成功刷新主键
                    this.bSaveResultComb = false;
                    this.bResultComb = false;
                } else {
                    this.$message.erro(res.errmsg);
                }
            } catch (e) {
                this.$message.warning(e);
            }
        },
        btnGoBack() {
            this.bSaveResultComb = false;
        },
        btn_openselEvent() {
            let mainheight = this.$refs.maindev.offsetHeight;
            this.showsearchbottom = !this.showsearchbottom;
            this.$nextTick(() => {
                if (this.showsearchbottom) {
                    this.pagetopstyle.height = "210px";
                    this.pagecenter.top = "213px";
                    this.tableheight = mainheight - 213;
                } else {
                    this.pagetopstyle.height = "105px";
                    this.pagecenter.top = "110px";
                    this.tableheight = mainheight - 110;
                }
            });
        },
        NextFocus(index) {
            if (index > 2) return false;
            var that = this;
            var focusIndex = index + 1;
            setTimeout(function () {
                that.$refs["input" + focusIndex].focus();
            }, 1);
        },
        btnSure() {
            console.log("this.ComList", this.ComList);
            this.searchmodel.resultcomb = "";
            this.tempCombList = XE.clone(this.$refs.nomatch_table.getTableData().fullData, true);
            this.bResultComb = false;
        },
        btnCancel() {
            // this.ComList=this.tempCombList
            this.ComList = XE.clone(this.tempCombList, true);
            this.bResultComb = false;
        },
        async getSavePower() {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS4/LIS442",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "get_savepower",
                    },
                });
                this.addPower = res;
            } catch (e) {
                this.$message.warning(e);
            }
        },
        reportcommchange(c, v) {
            this.searchmodel.reportcomm = v;
            this.reportcommDlg = false;
        },
        setExportColumn() {
            let allColumnList = [];
            this.$refs.xTable.getColumns().forEach((element) => {
                if (element.property) {
                    allColumnList.push({
                        title: element.title,
                        property: element.property,
                    });
                }
            });
            this.allTableCol = allColumnList;
            this.chooseColumndialogVisible = true;
        },
        saveExportColumn() {
            this.chooseColumndialogVisible = false;
        },
        popMultipleChk_R(e, fieldname, option, title) {
            let temp = XE.clone(option, true)
            this.option1 = []
            this.option2 = []
            if (e != "") {
                let k = e.split(",")
                k.forEach((item) => {
                    let ndata = temp.find((m) => m.data == item)
                    if (ndata != undefined && ndata != null) {
                        this.option2.push(ndata)
                    }
                })
                temp.forEach((item) => {
                    if (k.indexOf(item.data + "") < 0) {
                        this.option1.push(item)
                    }
                })
            } else {
                this.option1 = temp
            }
            this.fieldname = fieldname
            this.dialogMultipleVisible_R = true
        },
        closedialog_R(value, name) {
            if (value != "close") {
                let row = this.$refs.nomatch_table.getCurrentRow();
                if(row){
                    row.resistrules=value;
                }
            }
            this.dialogMultipleVisible_R = false
        },
        rptunitidChange(code,name){
            this.txtrptunit = code;
            this.rptunitname = name;
        }
    },
};
</script>

<style scoped>
::v-deep .el-checkbox__inner::after {
    border: 2px solid #000000 !important;
    box-sizing: content-box;
    content: "";
    border-left: 0 !important;
    border-top: 0 !important;
    height: 7px;
    left: 4px;
    position: absolute;
    top: 1px;
    transform: rotate(45deg) scaleY(0);
    width: 3px;
    transition: transform 0.15s ease-in 0.05s;
    transform-origin: center;
}
::v-deep .el-checkbox__input.is-disabled + span.el-checkbox__label {
    color: #000000;
    cursor: not-allowed;
}
::v-deep .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
    background-color: #ffffff !important;
}
::v-deep .el-input--suffix .el-input__inner {
    padding-right: 5px;
}
table tr td:nth-child(odd) {
    text-align: right;
    white-space: nowrap;
}
table tr td:nth-child(even) {
    text-align: left;
}
.pagetop {
    left: 0;
    right: 0;
    height: 200px;
    display: -webkit-box;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
    position: absolute;
    z-index: 99;
}
.pagemain {
    position: absolute;
    height: 90%;
    top: 0px;
    left: 0px;
    right: 0px;
    /* overflow: auto; */
    bottom: 40px;
}
.pagebottom {
    position: absolute;
    height: 45px;
    left: 0px;
    right: 0px;
    overflow: visible;
    bottom: 0px;
    z-index: 999;
}
</style>